import Vue from 'vue'
import Router from 'vue-router'
import Home from '@/view/home/index'
import HomeMain from '@/view/home/main/index'
import HomeSort from '@/view/home/sort/index'
import HomeCart from '@/view/home/cart/index'
import HomeMe from '@/view/home/me/index'
import Classify from '@/view/classify/index'

Vue.use(Router)

const router = new Router({
  routes: [
    {
      path: '/home',
      name: '首页',
      component: Home,
      redirect: '/home/main',
      children: [
        {
          path: 'main',
          name: '盒马',
          component: HomeMain
        },
        {
          path: 'sort',
          name: '分类',
          component: HomeSort
        },
        {
          path: 'cart',
          name: '购物车',
          component: HomeCart
        },
        {
          path: 'me',
          name: '我的',
          component: HomeMe
        }
      ]
    },
    {
      path: '/classify',
      name: '商城',
      component: Classify
    },
    {
      path: '*',
      redirect: '/home'
    }
  ]
})

// 设置点返回时统一滚动到页面顶部
router.beforeEach((to, from, next) => {
  window.scrollTo(0, 0)
  next()
})

export default router
